package com.ccrfid.rmc6.service.amq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

@Component
public class MqMsgProducer {
    private static final Logger logger = LoggerFactory.getLogger(MqMsgProducer.class);
    @Autowired
    @Qualifier("jmsQueueTemplate")
    private JmsTemplate jmsQueueTemplate;
    @Autowired
    @Qualifier("jmsTopicTemplate")
    private JmsTemplate jmsTopicTemplate;

    public void send2Queue(String queue, String msg) {
        logger.debug("send to queue: {}, msg: {}", queue, msg);
        jmsQueueTemplate.convertAndSend(queue, msg);
    }

    public void send2Topic(String topic, String msg) {
        logger.debug("send to topic: {}, msg: {}", topic, msg);
        jmsTopicTemplate.convertAndSend(topic, msg);
    }
}
